﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using NLBS.Data;
using NLBS.Entity;
using System.IO;
using System.Web;
using System.Web.UI.HtmlControls;

namespace NLBS.Control
{
   public class SkinDropDownList : DropDownList
    {
       public SkinDropDownList()
       {
           this.Items.Add(new ListItem("默认界面", "styles/evergreen/styles.css"));
           this.Items.Add(new ListItem("---------------------"));
           string[] fileEntries = Directory.GetDirectories(HttpContext.Current.Request.PhysicalApplicationPath + "styles");
           foreach (string path in fileEntries)
           {
               ListItem item = new ListItem(path.Substring(path.LastIndexOf("\\") + 1),"styles/" + path.Substring(path.LastIndexOf("\\") + 1) + "/styles.css");
               this.Items.Add(item);
           }
           this.SelectedIndex = 1;
           this.AutoPostBack = true;
       }

       protected override void OnTextChanged(EventArgs e)
       {
           base.OnTextChanged(e);
           if (this.SelectedIndex != 1)
           {
               HtmlLink link = (HtmlLink)this.Page.Master.FindControl("skin");
               link.Href = this.SelectedItem.Value;
               NLBS.Web.Cookie.SetSkinCookie("/"+this.SelectedItem.Value);
           }
       }
    }
}
